package Part_2;

import java.text.DecimalFormat;

//Needed for part 3 so warning => no big deal
import chapman.graphics.JPlot2D;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;

public class Simulation {
	
	//Needed for part 3 so warning => no big deal
	private static JPlot2D pl;

	public static void main(String[] args) {
		
		DecimalFormat df = new DecimalFormat("00");
		
		//difine vars ...
		//					00  01  02  03  04  05  06  07  08  09  10  11 
		double[] classes = {73, 63, 60, 65, 55, 53, 48, 47, 35, 37, 38, 39};
		double[] classesModified = new double[12]; 
		
		double[] class7 = new double[12]; 		//PART 3
		
		/*
		 * The main simulation program
		 */
		
		System.out.println("Class       : 0   1   2   3   4   5   6   7   8   9   10  11");
		System.out.println("------------------------------------------------------------");
		
		for(int semester = 0 ; semester < 12 ; semester++ ) {
			
			//the big simulation :s
			for(int i=0 ; i < classes.length ; i++) {
				/*
				 * 4 posibilities\
				 * - Quit
				 * - Redo
				 * - Previus
				 * - Pass
				 * 
				 * totaling 100%
				 */
				
				//failed students (students redo class)
				if (i == 7) {
					classesModified[i] = classesModified[i] + classes[i] * 0.05;
				} else {
					classesModified[i] = classesModified[i] + classes[i] * 0.12;
				}
				
				//students have to go back a class
				if(i != 0){
					classesModified[(i-1)] = classesModified[(i-1)] + classes[i] * 0.11;
				}
				
				//passed students to next class
				if(i != 11) {
					if (i == 7) {
						classesModified[(i+1)] = classesModified[(i+1)] + classes[i] * 0.77;
					} else {
						classesModified[(i+1)] = classesModified[(i+1)] + classes[i] * 0.7;
					}
				}
				// The failed ones are automaticly removed (sum of % != 100)
			}
			
			//transplant array
			for(int i = 0 ; i < classes.length ; i ++ ) {
				classes[i] = classesModified[i];
				classesModified[i] = 0;
			}
			
			//Store class #7 in a special array :)	  	  PART 3
			class7[semester] = classes[7];		//PART 3
			
			//default values
			classes[0] = 73;
			
			//dump array
			System.out.print(  "Semester " + df.format(semester) + " : ");
			for(int i=0 ; i < classes.length ; i++) {
				System.out.print((int) classes[i] + "  ");
			}
			System.out.println("");
		}
		
		System.out.println("------------------------------------------------------------");
		System.out.println("Simulation done!");
		System.out.println("");
		
		/*
		 * Make a bar graph
		 * PART 3
		 */
		
		// /*
		
		// some parameters ...
		double[] x = new double[12];
		double Xscale[]={0,11};
		
		// ... no comment
		for(int i=0 ; i< x.length ; i++) {
			x[i] = i;
		}
		
		// difine the looks of the graph
		pl = new JPlot2D(x , class7);
		pl.setPlotType(JPlot2D.BAR);
		pl.setXScale(Xscale);
		pl.setLineColor(Color.black);
		pl.setLineStyle(JPlot2D.LINESTYLE_SOLID);
		pl.setTitle( "The amount of students in class 7");
		pl.setXLabel("Semester");
		pl.setYLabel("# Students");
		pl.setGridState(JPlot2D.GRID_ON);
		JFrame fr = new JFrame("Some plot .....");
		
		WindowHandler l = new WindowHandler();
		fr.addWindowListener(l);
		
		//putting the graph in a layout and showing it 
		fr.getContentPane().add(pl, BorderLayout.CENTER);
		fr.setSize(400,500);
		fr.setVisible(true);
		
		
		//DUMP OF CLASS7 (array)
		System.out.println("Dump of the history of class 7");
		System.out.println("Semester   : 0   1   2   3   4   5   6   7   8   9   10  11");
		System.out.println("-----------------------------------------------------------");
		System.out.print("# Students : ");
		for(int i=0 ; i < class7.length ; i++) {
			System.out.print((int)class7[i] + "  ");
		}
		System.out.println("");
		System.out.println("-----------------------------------------------------------");
		
		// */
	}

}


